package com.umeox.watch.moto.launcher.fragment;

import android.graphics.Color;
import android.os.Build;
import android.view.View;

import androidx.viewpager2.widget.ViewPager2;

import com.umeox.moto.watch.themes.app.ThemeFragment;
import com.umeox.watch.moto.launcher.R;
import com.umeox.watch.moto.launcher.adapter.ChallengePagerAdapter;

import java.util.Arrays;

public class ChallengeFragment extends ThemeFragment {


    private ViewPager2 mPager;
    private View vPoint1;
    private View vPoint2;
    private ChallengePagerAdapter mPagerAdapter;


    @Override
    protected int getLayoutId() {
        return R.layout.frag_challenge;
    }

    @Override
    protected void initView(View rootView) {
        mPager = rootView.findViewById(R.id.pager);
        vPoint1 = rootView.findViewById(R.id.v_point_1);
        vPoint2 = rootView.findViewById(R.id.v_point_2);
        mPagerAdapter = new ChallengePagerAdapter(this);
        mPager.setOffscreenPageLimit(2);
        mPager.setAdapter(mPagerAdapter);
        mPagerAdapter.setFragments(Arrays.asList(new ChallengeStepsFragment(), new PedometerFragment()));
        mPager.setCurrentItem(0, false);
        mPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                setPoint(position);

            }
        });
        setPoint(0);
    }

    private void setPoint(int position) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (position == 0) {
                vPoint1.getBackground().mutate().setTint(Color.parseColor("#2EC26C"));
                vPoint2.getBackground().mutate().setTint(Color.parseColor("#662EC26C"));
            } else {
                vPoint1.getBackground().mutate().setTint(Color.parseColor("#662EC26C"));
                vPoint2.getBackground().mutate().setTint(Color.parseColor("#2EC26C"));
            }
        }
    }

}
